package deep.projects.newsapp.activities;

import android.os.Bundle;
import android.widget.EditText;

import com.wuxinwudai.android.util.RegexUtils;
import com.wuxinwudai.android.util.ToastUtils;
import com.wuxinwudai.android.util.ViewUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import deep.projects.newsapp.R;
import deep.projects.newsapp.app.Urls;
import okhttp3.Call;
import okhttp3.Response;

/**
 * @author 吾心无待 于2016年03月05日
 */
public class RetrievePasswordActivity extends BaseLayoutActivity {
    @BindView(R.id.et_mobile) EditText metMobile;

    @Override
    public int getLayoutId() {
        return R.layout.activity_retrieve_password;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        tvTitle.setText(R.string.title_activity_retrieve_password);
    }
    @OnClick(R.id.btn_next_step)void onNextStep(){
        String mobile = metMobile.getText().toString();
        if (!RegexUtils.isMobile(mobile)){
            ToastUtils.showShort(RetrievePasswordActivity.this,"手机号码格式不正确！");
            return;
        }
        ViewUtils.showLoadingDialog(this);
        OkHttpUtils.post().url(Urls.POST_REGISTER_URL).addParams("mobile",mobile).build().execute(new Callback<JSONObject>() {
            @Override
            public JSONObject parseNetworkResponse(Response response) throws Exception {
                return new JSONObject(response.body().string());
            }
            @Override
            public void onError(Call call, Exception e) {
                i("on Error:"+e.getMessage());
                ViewUtils.dismissLoadingDialog();
            }
            @Override
            public void onResponse(final JSONObject response) {
                try{
                    if (response.getBoolean("ok")){
                        //登录
                    }else{
                        ToastUtils.showShort(RetrievePasswordActivity.this,response.getString("message"));
                    }
                }catch (Exception ex){

                }
                ViewUtils.dismissLoadingDialog();
            }
        });
    }
}
